n=eval(input())
while n:
    m = eval(input())
    flag=0
    for i in range(0, m):
        s = input().split(' ')
        if i!=0:
            for j in range(0, i):
                if s[j] != '0':
                    if not flag:
                        print("NO")
                    flag = 1

    if not flag:
        print("YES")
    n-=1

